// src/router/index.js
import { createRouter, createWebHistory } from 'vue-router';
import index from '../views/index/index.vue';
import AboutView from '../views/AboutView.vue';
import NotFound from '../views/nofound/index.vue';
import List from '../views/list/index.vue';
 
const routes = [
  {
    path: '/',
    name: 'home',
    component: index,
  },
  {
    path: '/list',
    name: 'list',
    component: List,
  },
  {
    path: '/about',
    name: 'about',
    component: AboutView,
  },
  {
    path: '/404', 
    name: "404",
    component: NotFound,
  },
];
 const router = createRouter({
  history: createWebHistory(import.meta.env.VITE_APP_BASE),
  routes,
});
router.beforeEach((to, from, next) => {
  if (to.matched.length === 0) {
    next({ name: "404" }); 
  } else {
    next();
  }
});
export default router;